<%@ include file="/common/taglibs.jsp"%>
<%@ taglib prefix="form" uri="http://www.springframework.org/tags/form"%>

<probiz:pageHeading entityName="${smsQueue.smsQueueName}" entityHeadingKey="smsQueueDetail.heading" />
<content tag="buttons">
	<c:if test="${not empty smsQueue || smsQueue.status == 0}">
		<probiz:iconBtn btnType="save" onclick="return fnDoSave(this);" />
	</c:if>
	<c:if test="${not empty smsQueue.smsQueueId}">
	<probiz:iconBtn btnType="sms" btnTextKey="common.iconBtn.reSend" onclick="return reSendSms(this);" />
	</c:if>
	<c:if test="${empty smsQueue.smsQueueId }">
	<probiz:iconBtn btnType="sms" onclick="return reSendSms(this);" />
	</c:if>	
	<probiz:iconBtn btnType="back" onclick="return fnDoCancelForm(this);" />
</content>
<probiz:showBindErrors bindPath="smsQueue.*" />
<div class="top clearfix">
	<ul class="tab">
		<li class="curr"><span><fmt:message key="smsQueueDetail.heading"/></span></li>
	</ul>
</div>
<div class="modify">
	<form:form method="post" cssClass="mainForm" id="smsQueue" commandName="smsQueue"
			action="${ctxPath}/tool/smsQueue.html" onsubmit="return validateSmsQueue(this);">
		<input type="hidden" name="smsQueueId" id="smsQueueId" value="${smsQueue.smsQueueId}"/> 
		<input type="hidden" name="multiIds" id="multiIds" value="${smsQueue.smsQueueId}"/> 
		<input type="hidden" name="doAction" id="doAction" value=""/> 
		<table width="100%" border="0" cellspacing="0" cellpadding="0" class="com_modi_table">
		<tr>
			<th colspan="2" class="title"><h4><fmt:message key="smsQueueDetail.heading"/></h4></th>
		</tr>
 		<tr>
			<th>
				<fmt:message key="smsQueue.phoneNumbers" />(<span class="red">*</span>):
			</th>
			<td>
				<textarea id="phoneNumbers" name="phoneNumbers" class="textareatxt" cols="50" rows="5">${smsQueue.phoneNumbers }</textarea>
				<fmt:message key="sms.mobilephone.tip" />
			</td>
		</tr>
		<tr>
			<th>
				<fmt:message key="smsQueue.smsContent" />(<span class="red">*</span>):
			</th>
			<td>
				<textarea id="smsContent" name="smsContent" class="textareatxt" cols="50" rows="8">${smsQueue.smsContent }</textarea>
				<fmt:message key="sms.msgContent.tip" />
			</td>
		</tr>
		<%--
		<probiz:input property="customerNames" />
 		 --%>
 		<tr>
			<th class="label_width_1">
				<fmt:message key="smsQueue.status"/>
			</th>
			<td>
				<c:choose>
					<c:when test="${smsQueue.status eq 1 }"><fmt:message key="smsQueue.status1"/></c:when>
					<c:otherwise><fmt:message key="smsQueue.status0"/></c:otherwise>
				</c:choose>
			</td>
		</tr>
 		<probiz:formText label="smsQueue.sendStatus" value="${smsQueue.sendStatus}" />
 		<c:set var="csendTime"><fmt:formatDate value="${smsQueue.sendTime}" pattern="yyyy-MM-dd HH:mm:ss" /></c:set>
 		<probiz:formText label="smsQueue.sendTime" value="${csendTime}" />
 		<c:set var="ccreatTime"><fmt:formatDate value="${smsQueue.createTime}" pattern="yyyy-MM-dd HH:mm:ss" /></c:set>
 		<probiz:formText label="common.message.createTime" value="${ccreatTime}" />
   	</table>
</form:form>
</div>

<v:javascript formName="smsQueue" staticJavascript="false" />
<script type="text/javascript">
    document.forms["smsQueue"].elements["phoneNumbers"].focus();
    $j(document).ready(function () {
		__FMTExtend = {
			sms_nullContent_tip:"<fmt:message key="sms.nullContent.tip"/>",
			sms_msgContent_tip:"<fmt:message key="sms.msgContent.tip"/>",
			sms_mobilephone_tip:"<fmt:message key="sms.mobilephone.tip"/>",
			sms_mobilephone_tip1:"<fmt:message key="sms.mobilephone.tip1"/>",
			sms_send_tip:"<fmt:message key="sms.send.tip"/>"
		};
		$j.extend(__FMT, __FMTExtend);
	});	
    
	function validateSmsQueue(){
		
		var phoneNumbers = $("phoneNumbers").value;
		var msgContent = $("smsContent").value;
		
		if(trim(phoneNumbers)=="" || trim(msgContent)==""){
			alert(__FMT.sms_nullContent_tip);
			return false;
		}
		
		if(msgContent.length>400){
			alert(__FMT.sms_msgContent_tip);
			return false;
		}
		
		var numbs = phoneNumbers.split(",");
		if(numbs.length>1100){
			alert(__FMT.sms_mobilephone_tip);
			return false;
		}
		var partten = /^(13[0-9]|15[0|3|6|7|8|9]|18[6|8|9])\d{8}$/;
		var stasss  = false;
		for(var i=0;i<numbs.length;i++){
			if(!partten.test((numbs[i]))){
				stasss = true;
				break;
			}
		}
		if(stasss){
			alert(__FMT.sms_mobilephone_tip1);
			return false;
		}
		
		return true;
	}
	
	function reSendSms(obj){
		if (validateSmsQueue()) {
			if(confirm(__FMT.sms_send_tip+ " " + $("phoneNumbers").value+" ?")){
				$("doAction").value="sendSms2Form";
				$("smsQueue").submit();			}
		}
	}
	function reSendMsgCallback(data){
		window.location.href=__ctxPath + "/tool/smsQueue.html";
	}
</script>
